package name.huzhenbo.java.threads;

class PrimitiveHolder {

    private int i = 0;
    private double d = 0.00;
    private long l = 0;

    public int getI() {
        return i;
    }

    /**
     * ++ is not atomic, it contains a read and write. Also, we should shynchronize it because of memory model, to let
     * other threads "see" the change.
     */
    public synchronized void increaseI() {
        this.i++;
    }

    /**
     * The read and write of double or long should be synchronized.
     */
    public synchronized double getD() {
        return d;
    }

    public synchronized void increaseD() {
        this.d += 1.00;
    }

    public synchronized long getL() {
        return l;
    }

    public synchronized void increaseL() {
        this.l += 1;
    }
}
